﻿
using System;
using System.Data;
using System.Collections.Generic;
using NetDisk_WebService.Model;
namespace NetDisk_WebService.BLL
{
	/// <summary>
	/// 网盘
	/// </summary>
	public partial class NetDisk
	{
		private readonly NetDisk_WebService.DAL.NetDisk dal=new NetDisk_WebService.DAL.NetDisk();
		public NetDisk()
		{}

        #region webservice
        /// <summary>
        /// 测试数据库连接是否成功
        /// <creator>wangl</creator>
        /// <date>2013-02-17</date>
        /// </summary>
        /// <returns>1 成功 -1 失败</returns>
        public int DBConnectTest()
        {
            return dal.DBConnectTest();
        }

        /// <summary>
        /// 获取数据库服务器系统时间
        /// <creator>wangl</creator>
        /// <date>2013-02-17</date> 
        /// </summary>
        /// <returns>null为获取失败</returns>
        public DateTime GetServerDatetime()
        {
            return dal.GetServerDatetime();
        }

        /// <summary>
        /// 是否存在该记录
        /// <creator>sunlj</creator>
        /// <date>2014-11-24</date> 
        /// </summary>
        /// <param name="fLogID">用户登录号</param>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <returns>是否存在</returns>
        public bool Exists(string fLogID, string fEntityNo)
        {
            return dal.Exists(fLogID, fEntityNo);
        }


        /// <summary>
        /// 获取用户密码
        /// <creator>sunlj</creator>
        /// <date>2014-11-24</date> 
        /// </summary>
        /// <param name="logid">登录ID</param>
        /// <returns></returns>
        public string GetUserPassword(string logID, string FEntityNo)
        {
            return dal.GetUserPassword(logID, FEntityNo);
        }

        /// <summary>
        /// 获取用户名
        /// <creator>sunlj</creator>
        /// <date>2014-11-24</date> 
        /// </summary>
        /// <param name="logid">登录ID</param>
        /// <returns></returns>
        public string GetUserFullname(string logID, string FEntityNo)
        {
            return dal.GetUserFullname(logID, FEntityNo);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public decimal AddNetDisk(Model.NetDisk model)
        {
            return dal.AddNetDisk(model);
        }

        /// <summary>
        /// 增加一条数据（覆盖文件）
        /// <creator>sunlj</creator>
        /// <date>2014-12-12</date>
        /// </summary>
        public decimal AddNetDiskCover(Model.NetDisk model)
        {
            return dal.AddNetDiskCover(model);
        }


        /// <summary>
        /// 获取网盘列表
        /// <create>sunlj</create>
        /// <date>2014-12-08</date>
        /// </summary>
        /// <param name="FID"></param>
        /// <param name="entityNo"></param>
        /// <param name="orderField"></param>
        /// <returns></returns>
        public List<Model.NetDisk> GetList(decimal FParentID, string entityNo, string orderField)
        {
            DataSet ds = dal.GetList(FParentID, entityNo, orderField);
            return DataTableToList(ds.Tables[0]);

        }

        /// <summary>
        /// 获取网盘列表
        /// <create>sunlj</create>
        /// <date>2014-12-08</date>
        /// </summary>
        /// <param name="strWhere"></param>
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public List<Model.NetDisk> GetModelList(string strWhere, string entityNo)
        {
            DataSet ds = dal.GetModelList(strWhere, entityNo);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获取网盘列表(递归)
        /// <create>sunlj</create>
        /// <date>2014-12-08</date>
        /// </summary>
        /// <param name="FParentID"></param>
        /// <param name="entityNo"></param>
        /// <param name="orderField"></param>
        /// <returns></returns>
        public List<Model.NetDisk> GetListCTE(decimal FParentID, string entityNo, string strWhere, string orderField)
        {
            DataSet ds = dal.GetListCTE(FParentID, entityNo,strWhere, orderField);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.NetDisk> DataTableToList(DataTable dt)
        {
            List<Model.NetDisk> modelList = new List<Model.NetDisk>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.NetDisk model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }


        /// <summary>
        /// 获得数据列表
        /// <creator>sunlj</creator>
        /// <date>2014-09-22</date>
        /// </summary>
        public List<Model.NetDisk> GetDirByFLogID(string FEntityNo, string FLogID)
        {
            DataSet ds = dal.GetDirByFLogID(FEntityNo, FLogID);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 同一路径下的相同文件夹
        /// <creator>sunlj</creator>
        /// <date>2014-12-12</date>
        /// </summary>
        /// <param name="FParentID"></param>
        /// <param name="FName"></param>
        /// <param name="FEntityNo"></param>
        /// <param name="oldFID"></param>
        /// <returns></returns>
        public decimal GetSame(decimal FParentID, string FName, string FEntityNo,string oldFID="")
        {
            return dal.GetSame(FParentID, FName, FEntityNo, oldFID);
        }

        /// <summary>
        /// 获取当前目录的所有父级目录
        /// <creator>sunlj</creator>
        /// <date>2014-09-25</date>
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetListPre(decimal id)
        {
            DataSet ds = dal.GetListPre(id);
            return ds.Tables[0];
        }

         /// <summary>
        /// 判断是否将当前文件夹移动到它的子文件夹
        /// </summary>
        /// <param name="FParentID"></param>
        /// <param name="FID"></param>
        /// <param name="FEntityNo"></param>
        /// <returns></returns>
        public bool IsErrorMoveParentDirChildDir(decimal FParentID, decimal FID, string FEntityNo)
        {
            return dal.IsErrorMoveParentDirChildDir(FParentID, FID, FEntityNo);
        }
        /// <summary>
        /// 删除目录
        /// <creator>sunlj</creator>
        /// <date>2014-09-22</date>
        /// </summary>
        /// <param name="id"></param>
        public void deleteNetDisk(decimal id,string entityNo)
        {
            dal.deleteNetDisk(id, entityNo);
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>sunlj</creator>
        /// <date>2014-09-22</date>
        /// </summary>
        public Model.NetDisk GetModel(decimal FID)
        {
            return dal.GetModel(FID);
        }

        /// <summary>
        /// 移动文件位置
        /// <creator>sunlj</creator>
        /// <date>2014-09-30</date>
        /// </summary>
        /// <param name="FID"></param>
        /// <param name="newParentID"></param>
        public void moveNetDisk(decimal FID, decimal newParentID)
        {
            dal.moveNetDisk(FID, newParentID);
        }

        /// <summary>
        /// 重命名
        /// <creator>sunlj</creator>
        /// <date>2014-09-30</date>
        /// </summary>
        /// <param name="FID"></param>
        /// <param name="FName"></param>
        public void renameNetDisk(decimal FID, string FName)
        {
            dal.renameNetDisk(FID, FName);
        }

        /// <summary>
        /// 获取根目录
        /// <creator>sunlj</creator>
        /// <date>2014-12-18</date>
        /// </summary>
        /// <param name="logId"></param>
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public Model.NetDisk GetRoot(string logId, string entityNo)
        {
            return dal.GetRoot(logId, entityNo);
        }

        /// <summary>
        /// 获取有子文件的文件夹
        /// <creator>sunlj</creator>
        /// <date>2015-1-30</date>
        /// </summary>
        /// <param name="entityNo"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public List<Model.NetDisk> GetDirectoryHaveChild(string entityNo, string ids)
        {
            DataSet ds = dal.GetDirectoryHaveChild(entityNo, ids);
            return DataTableToList(ds.Tables[0]);
        }
        #endregion

    }
}

